package ordinaryArray;

/*
 *@description 删除有序数组中的重复项
 *@author hkfan
 *@version 1.0
 *@create 2025/5/19 17:18
 */
public class LeetCode_26 {



    public int removeDuplicates(int[] nums) {
        //1. 特殊情况返回
        if (nums.length == 1) {
            return 1;
        }
        if (nums.length == 0) {
            return 0;
        }
        //2. 定义指针
        int l = 0, r = 1;
        while (r < nums.length) {
            if (nums[r] == nums[l]) {
                r++;
            } else {
                l++;
                nums[l] = nums[r];
            }
        }
        return l+1;
    }

}
